package com.xxgc.spring.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.springframework.beans.PropertyAccessException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;
import javax.xml.bind.PropertyException;
import java.beans.PropertyVetoException;
import java.util.ResourceBundle;

@Configuration
@ComponentScan("com.xxgc.spring")
@PropertySource({"classpath:init.properties","classpath:jdbc.properties"})
public class SpringConfiguration {
    @Value("${jdbc.test.driver}")
    private  String driver;
    @Value("${jdbc.test.url}")
    private  String url;
    @Value("${jdbc.test.username}")
    private  String username;
    @Value("${jdbc.test.password}")
    private  String password;


    @Bean("dataSource")
    public DataSource getDataSource() throws PropertyVetoException{

        ComboPooledDataSource dateSource = new ComboPooledDataSource();
        dateSource.setDriverClass(driver);
        dateSource.setJdbcUrl(url);
        dateSource.setUser(username);
        dateSource.setPassword(password);
        return  dateSource;
    }
}
